//
//  CountBuyViewController.m
//  BingoWaterfallFlowDemo
//
//  Created by giikylee on 16/8/25.
//  Copyright © 2016年 Bing. All rights reserved.
//

#import "CountBuyViewController.h"
#import "XHLWaterLayout.h"
#import "CountBuyCollectionViewCell.h"
#import "ZLScrolling.h"
static const NSInteger XHLDefaultColumnCount = 2;
static const CGFloat XHLDefaultRowMargin = 5;
static NSString *cellID = @"counBuyCell";
@interface CountBuyViewController ()<XHLWaterLayoutDelegate,UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,strong)UICollectionView * collectView;
@property(nonatomic,strong)UIView *photobrowsView;
@end

@implementation CountBuyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    XHLWaterLayout * layOut = [[XHLWaterLayout alloc] init];
    layOut.delegate = self;
    self.collectView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, wKscreen, hKscreen) collectionViewLayout:layOut];
    self.collectView.backgroundColor = [UIColor whiteColor];
    self.collectView.delegate =self;
    self.collectView.dataSource =self;
    [self.view addSubview:self.collectView];
    
    [self.collectView registerNib:[UINib nibWithNibName:@"CountBuyCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:cellID];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CountBuyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.picImageView.image = [UIImage imageNamed:@"sp1.png"];
    if (indexPath.row == 2) {
        cell.picImageView.image = [UIImage imageNamed:@"fm.jpg"];
    }
    return cell;
}

-(CGFloat)waterLayout:(UICollectionViewLayout *)waterLayout itemWidth:(CGFloat)itemWidth indexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 2) {
        return wKscreen * 154 / 173 + 50;
    } else {
        return wKscreen * 139 / 219 + 50 ;
    }
}

-(NSInteger)columnCountInWaterflowLayout:(UICollectionViewLayout *)layout
{
    return XHLDefaultColumnCount;
}
-(CGFloat)rowMarginInWaterflowLayout:(UICollectionViewLayout *)layout
{
    return XHLDefaultRowMargin;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.photobrowsView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.photobrowsView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
    [self.view addSubview:self.photobrowsView];
    
    NSArray *url = @[@"http://192.168.2.55/CCB_index/images/master_style01.jpg", @"https://gd2.alicdn.com/bao/uploaded/i2/TB1zjFTHpXXXXb4XXXXXXXXXXXX_!!0-item_pic.jpg", @"http://192.168.2.55/CCB_index/images/master_style01.jpg", @"http://d.hiphotos.baidu.com/lvpics/w=1000/sign=81bf893e12dfa9ecfd2e521752e0f603/242dd42a2834349b705785a7caea15ce36d3bebb.jpg", @"https://gd2.alicdn.com/bao/uploaded/i2/2832311541/TB2KoN3X6zyQeBjy0FjXXc5CVXa_!!2832311541.jpg"];
    NSMutableArray *urlarr = [NSMutableArray array];
    for (NSString *str in url) {
        NSURL *imurl = [NSURL URLWithString:str];
        [urlarr addObject:imurl];
    }
    //NSArray *arr = @[@"photo_sample_01",@"photo_sample_02",@"photo_sample_03",@"photo_sample_04",@"photo_sample_05",@"photo_sample_06",@"photo_sample_07"];
    ZLScrolling *zl = [[ZLScrolling alloc]initWithCurrentController:self frame:CGRectMake(0, 60, wKscreen, hKscreen-120-64) photos:urlarr placeholderImage:[UIImage imageNamed:@"timeline_image_loading"]];
//    [zl.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
    //zl.pageControl.pageIndicatorTintColor = [UIColor redColor];
    zl.pageControl.backgroundColor = [UIColor clearColor];
    [self.photobrowsView addSubview:zl.view];
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self  action:@selector(handlePan:)];
    [self.photobrowsView addGestureRecognizer:tapGestureRecognizer];
}
-(void)handlePan:(UITapGestureRecognizer *)recognizer
{
    [UIView animateWithDuration:0.5f animations:^{
        self.photobrowsView.frame = CGRectMake(0, hKscreen, wKscreen, 0);
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
